<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="sun.applet.resources.MsgAppletViewer_it"%>
<%@page import="utility.connections"%>
<%@page import="java.sql.*" %>
<%@include file="../../hom/chkUser.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>SELEZIONA SOTTOCATEGORIA</title>
		<script type="text/javascript">
			function insert()
			{
				codice 			= document.frmSubCat.txtCodice.value;
				categoria 		= document.frmSubCat.cmbCategoria.value;
				nome 			= document.frmSubCat.txtNome.value;
				if(nome.length==0)
				{
					alert("campo nome non inserito");
					document.frmSubCat.action="";
				}
				if(categoria.length==0)
				{
					alert("nessuna categoria selezionata");
					document.frmSubCat.action="";
				}
				document.frmSubCat.submit();
			}
			function del()
			{
				codice 			= document.frmSubCat.txtCodice.value;
				categoria 		= document.frmSubCat.cmbCategoria.value;
				nome 			= document.frmSubCat.txtNome.value;
				if(nome.length==0 || categoria.length==0)
				{
					alert("campo nome non inserito e/o nessuna categoria selezionata");
					document.frmSubCat.action="";
				}
				else
					document.frmSubCat.action="../../Delete_subcat";
				document.frmSubCat.submit();
			}
			function back()
			{
				location.href="../hadm.jsp";
			}
			function setOrder(index)
			{
				qry = "select_subcat.jsp?order="+index;
				location.href = qry;
			}
			
			function pickRow(row)
			{
				location.href = "select_subcat.jsp?pick=1&&row="+row+"&order=1";
			}
		</script>
		<script type="text/javascript" src="../js/immagini.js" ></script>
	    <style type="text/css">
<!--
.style1 {color: #000000}
.style3 {color: #000000; font-weight: bold; }
-->
        </style>
</head>
	<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
	<body>
	<%!
		Connection conn;
		Statement st;
		ResultSet rs;
		String cod="";
		String cat="";
		String nome="";
		String subcat;
		String forn;
		String user;
		String cerca;
		String qry;
		String undel="0";
	 %>
	 <%
	 	if(request.getParameter("undel")!=null)
	 		pageContext.include("undel.jsp");
	 	String pick = "" + request.getParameter("pick");
	 	System.out.println(pick);
	 	if(pick.equalsIgnoreCase("1"))
	 	{
	 		conn=connections.getConnection();
	 		st=connections.getStatement();
	 		qry = "select * from sottocategoriabene where codice = " + request.getParameter("row");
	 		rs = st.executeQuery(qry);
	 		rs.next();
	 		cod = rs.getString("codice");
	 		nome = rs.getString("nome");
	 		cat = rs.getString("categoriabene");
	 		rs.close();
	 		st.close();
	 		conn.close();
	 	}
	 	else
	 	{
	 		cod = "";
	 		nome = "";
	 		cat = "";
	 	}
	 	
	  %>
		<form name="frmSubCat" method="post" action="../../insert_subcat">
		  <table width="100%" border="0" cellspacing="1" cellpadding="0">
	        <tr>
	          <td width="16%"><div align="right">CODICE:</div></td>
	          <td width="84%"><input type="text" name="txtCodice" value =<%=cod %> 
	          ></td>
	        </tr>
	        
	        <tr>
	          <td><div align="right">NOME::</div></td>
	          <td><input type="text" name="txtNome" value = 
	          <%=nome%>></input></td>
            </tr>
	        <tr>
	          <td><div align="right">CATEGORIA:</div></td>
	          <td><select name="cmbCategoria">
	            <option VALUE="">SELEZIONA UNA CATEGORIA</option>
	            <%
	            	Connection cn = connections.getConnection();
	            	Statement  xt = connections.getStatement();
	            	ResultSet  xs = xt.executeQuery("select * from categoriabene order by sigla");
	            	while (xs.next())
	            	{
	            		String rsCat = "" + xs.getString("sigla");
	            		if(rsCat.equalsIgnoreCase(cat))
	            			out.println("<option selected=\"selected\" value=\""+rsCat+"\">"+rsCat+"</option>");
	            		else
	            			out.println("<option value=\""+rsCat+"\">"+rsCat+"</option>");
	            	}
	            	xs.close();
	            	xt.close();
	            	cn.close();
	             %>
	            </select>	          </td>
	        </tr>
	        <tr>
	          <td><div align="right"></div></td>
	          <td><input name="cmdNew" type="submit" id="cmdNew" onClick="this.form.action='select_subcat.jsp?order=1&pick=0'" value="NUOVO">
	            <input type="submit" name="cmdCerca" value="AGGIUNGI" onClick="javascript:insert()">
	            <input name="cmdModifica" type="submit" id="cmdModifica" onClick="javascript:insert()" value="MODIFICA"> 
	              <input type="submit" name="cmdBack" value="ELIMINA" onClick="javascript:del()" >
	              <input type="submit" name="cmdBack2" value="INDIETRO" onClick="this.form.action='../hadm.jsp'"></td>
	        </tr>
	      </table>
		</form>
		<p align="center">ELENCO CATEGORIE </p>
		<table width="100%" border="1" cellspacing="1" cellpadding="0" style="border:1px solid;">
          <tr>
            <td width="4%" align="center" bgcolor="#FFFFFF" class="style3" style="border:1px solid;" >PROG</td>
            <td width="19%" align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><a href="javascript:setOrder(1)"><span class="style3">CODICE</span></a></td>
            <td width="30%" align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><a href="javascript:setOrder(2)"><span class="style3">NOME</span></a></td>
			<td width="23%" align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><a href="javascript:setOrder(3)"><span class="style3">CATEGORIA</span></a></td>
			<td width="24%" align="center" bgcolor="#FFFFFF" style="border:1px solid;" ><span class="style3">ELIMINA</span></td>
		  </tr>
          <%
				
				Connection conn=connections.getConnection();
				Statement st=connections.getStatement();
				int order = Integer.parseInt(request.getParameter("order"));
				String qry = "SELECT * FROM SOTTOCATEGORIABENE ORDER BY " + order;
				ResultSet rs = st.executeQuery(qry);
				int i=0;
					
				if(rs.isBeforeFirst()&&rs.isAfterLast())
				{
					//Avvisare che non ci sono record!!!!
				}
				else
				{
					while (rs.next())
					{
						String color;
	              		String bordercell;
	              		
	              		i++;
	              		
	              		if (i%2==0)
	              		{
	              			color ="\"#E0E0E0\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		else
	              		{
	              			color = "\"#EFFFEF\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		
	              		out.println("<tr>");
	              		out.println("<td align=\"right\"" +bordercell+" bordercolor=\"#555555\" bgcolor = "+color+"><span class=\"style1\">" + i + "</span></td>"); //prog.
	              		out.println("<td align=\"center\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+"><span class=\"style1\"><a href=\"javascript:pickRow("+rs.getString("codice")+")\">"+rs.getString("codice")+"</a></span></td>");
						out.println("<td align=\"center\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+"><span class=\"style1\">"+rs.getString("nome")+"</span></td>");
						out.println("<td align=\"center\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+"><span class=\"style1\">"+rs.getString("categoriabene")+"</span></td>");
	              		out.println("<td align=\"center\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+"><span class=\"style1\"><input type=\"checkbox\" name=\"chkDel\" value=\"\"></span></td>");
	              		out.println("</tr>");
	              	}
	              		out.println("</tr>");
				}
			
			rs.close();
			st.close();
             %>
        </table>
		<p>&nbsp;</p>
	</body>
</html>